/*
 * mirror.cpp
 *
 *  Created on: Jul 23, 2012
 *      Author: xkq
 */


#include "BSTNode.h"
#include <iostream>
#include <stack>

using namespace std;

void mirror_recursively(BSTNode *&root){
	if(!root) return;

	BSTNode *tmp = root->left;
	root->left=root->right;
	root->right=tmp;

	if(root->left)
		mirror_recursively(root->left);
	if(root->right)
		mirror_recursively(root->right);
}

void mirror_iteratively(BSTNode *root){
	if(!root) return;

	stack<BSTNode *> s;
	s.push(root);
	while(!s.empty()){
		BSTNode *p=s.top();
		s.pop();
		BSTNode *tmp=p->right;
		p->right=p->left;
		p->left=tmp;

		if(p->left)
			s.push(p->left);
		if(p->right)
			s.push(p->right);
	}
}
